home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Shareware / Programare / restuner / ResTuner_setup.exe / {app} / restuner.chm / example_c.txt < prev    next >
Text File  |  2005-01-11  |  4KB  |  141 lines

  1. //-----------------------------------------------------------------------------
  2. // PE Explorer/Resource Tuner Demo Plug-In
  3. // (c)2001 by Yuri Rai & Mike Caetano/Heaventools ltd.
  4. // http://www.heaventools.com
  5. //
  6. // C++
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <windows.h>
  10.  
  11. #include "globals.h"
  12.  
  13. // ---------------------------------------------------------------------------
  14. // ResTuner MEMORY ALLOCATOR FUNCTION POINTER TYPEDEF
  15. typedef    void * __stdcall (*pfnMemoryAllocator)(DWORD);
  16.  
  17. // ---------------------------------------------------------------------------
  18. // ResTuner CALLBACK FUNCTION FUNCTION POINTER TYPEDEF
  19. typedef    void __stdcall (*pfnPGICallBack)(DWORD, DWORD, LPCTSTR);
  20.  
  21. // ---------------------------------------------------------------------------
  22. // ResTuner PLUGIN INTERFACE STRUCTURE
  23. typedef struct tagPGIParamsBlock
  24. {
  25.     pfnMemoryAllocator pMemAllocator; // function pointer to ResTuner supplied 
  26.                                       // memory allocation
  27.     pfnPGICallBack pCallBack;         // function pointer to ResTuner callback 
  28.                                       // function
  29.     LPVOID pInBuff;                   // pointer to input buffer
  30.     LPVOID pOutBuff;                  // pointer to output buffer filled by plugin
  31.     DWORD dwInSize;                   // size in bytes of input buffer
  32.     DWORD dwOutSize;                  // size in bytes of output buffer set by plugin
  33.     DWORD dwInterface;                // read only interface ID
  34.     DWORD dwIndex;                    // read only plugin index
  35. }
  36. PGIParamsBlock, *PPGIParamsBlock;
  37.  
  38. // ---------------------------------------------------------------------------
  39. // GLOBAL VARIABLES
  40.  
  41. LPCTSTR szPluginName = SZPLUGINNAME;
  42.  
  43. DWORD   evID_PostLogInfo = 0;
  44.  
  45. // ---------------------------------------------------------------------------
  46. // EXPORT FUNCTION PROTOTYPES
  47. void __stdcall PexRegisterPlugIn(LPCTSTR *);
  48. void __stdcall PexAboutPlugIn(void);
  49. BOOL __stdcall PexPreloadImage(PPGIParamsBlock);
  50.  
  51. // ---------------------------------------------------------------------------
  52. // EXPORT FUNCTION IMPLEMENTATIONS
  53.  
  54. // ---------------------------------------------------------------------------
  55. // ResTuner R E G I S T E R P L U G I N
  56.  
  57. void __stdcall __declspec(dllexport) PexRegisterPlugIn(LPCTSTR *ppPluginName)
  58. {
  59.     *ppPluginName = szPluginName;
  60. }
  61.  
  62.  
  63. // ---------------------------------------------------------------------------
  64. // ResTuner A B O U T P L U G I N
  65.  
  66. void __stdcall __declspec(dllexport) PexAboutPlugIn(void)
  67. {
  68.     TCHAR szBuffer[MAX_PATH];
  69.     ZeroMemory(szBuffer,MAX_PATH);
  70.     wsprintf(szBuffer, TEXT("%s\r\n%s"), szPluginName, SZVERSION);
  71.     MessageBox(NULL, szBuffer, TEXT("About"), MB_OK|MB_ICONINFORMATION);
  72. }
  73.  
  74.  
  75. // ---------------------------------------------------------------------------
  76. // ResTuner(P E X) P R E L O A D I M A G E
  77.  
  78. BOOL __stdcall __declspec(dllexport) PexPreloadImage(PPGIParamsBlock pPGIPB)
  79. {
  80.  
  81.     // assume the worst :-)
  82.     BOOL result = FALSE;
  83.  
  84.     // setup messages for ResTuner log window
  85.     LPCTSTR DemoMessage1 = "Emulating Execution...";
  86.     LPCTSTR DemoMessage2 = "Allocating memory ...";
  87.     LPCTSTR DemoMessage3 = "Copy InBuff to OutBuff...";
  88.     LPCTSTR DemoMessage4 = "Runtime error: PexPreloadImage";
  89.  
  90.     // assign function pointers to local variables
  91.     pfnMemoryAllocator MA = pPGIPB->pMemAllocator;
  92.     pfnPGICallBack CB = pPGIPB->pCallBack;
  93.  
  94.     __try
  95.     {
  96.  
  97.         // announce plugin invocation
  98.         if ( CB != NULL ) {
  99.             CB(pPGIPB->dwInterface, evID_PostLogInfo, DemoMessage1);
  100.         }
  101.  
  102.         // announce action preparation
  103.         if ( CB != NULL ) {
  104.              CB(pPGIPB->dwInterface, evID_PostLogInfo, DemoMessage2);
  105.         }
  106.  
  107.         // set output buffer size parameter
  108.           pPGIPB->dwOutSize = pPGIPB->dwInSize;
  109.  
  110.         // let ResTuner allocate shared memory for output buffer
  111.         pPGIPB->pOutBuff = MA(pPGIPB->dwInSize);
  112.  
  113.         // transfer contents to output buffer
  114.         CopyMemory(pPGIPB->pOutBuff, pPGIPB->pInBuff, pPGIPB->dwInSize);
  115.  
  116.         // announce action success
  117.         if ( CB != NULL ) {
  118.              CB(pPGIPB->dwInterface, evID_PostLogInfo, DemoMessage3);
  119.         }
  120.  
  121.         // all systems go!
  122.         result = TRUE;
  123.  
  124.     }
  125.     __except ( EXCEPTION_EXECUTE_HANDLER )
  126.     {
  127.  
  128.         // announce error
  129.         if ( CB != NULL ) {
  130.              CB(pPGIPB->dwInterface, evID_PostLogInfo, DemoMessage4);
  131.          }
  132.  
  133.     }
  134.  
  135.     // return status
  136.     return(result);
  137.  
  138. }
  139.  
  140. // ---------------------------------------------------------------------------
  141.